<template>
  <div class="notificationDetails warp">
    <!-- <div class="head">
      <router-link to="/message">
      <div class="mar-right-10">消息中心</div>
      </router-link>
      <div class="arrow" />
      <div class="mar-right-10">公告详情</div>
    </div> -->
    <div v-loading="loading" class="messageDetail">
      <h1>{{ detail.noticeTitle }}</h1>
      <div class="date">{{ detail.createTime }}</div>
      <el-divider />
      <div class="messageInfo" v-html="detail.noticeContent" />
    </div>
  </div>
</template>

<script>
// import Cookie from 'js-cookie'
import { mapGetters, mapMutations } from 'vuex'
// import {
//   getUserInfo
// } from '@/api/user/user.js'
// import {
//   getNoticeDetail
// } from '@/api/user/notice.js'
export default {
  name: 'NotificationDetails',
  data() {
    return {
      detail: {},
      loading: false
    }
  },
  computed: {
    ...mapGetters([
      'noticeId'
    ])
  },
  watch: {
    noticeId: {
      handler(newVal, oldVal) {
        if (newVal !== oldVal) {
          this.getDetail()
        }
      }
    }
  },

  mounted() {
    this.getDetail()
  },

  methods: {
    ...mapMutations({
      setUserInfo: 'SET_USERINFO'
    }),
    async getDetail() {
      this.loading = true
      // const response = await getNoticeDetail({ noticeId: this.$route.query.id })
      // const res = response.data
      // if (res.code === '200') {
      //   this.detail = res.data
      //   if (Cookie.get('token')) {
      //     this.getUserInfoData()
      //   }
      //   this.loading = false
      // } else {
      //   this.$message.warning(res.message)
      // }
    },
    async getUserInfoData() {
      // const response = await getUserInfo()
      // const res = response.data
      const res = {
        'code': '200',
        'data': {
          'buyerUserId': 2125,
          'name': 'MJ77465',
          'sex': '男',
          'birthday': '2022-12-07',
          'wechatOpenId': '',
          'wechatUnionId': '',
          'wechatName': '',
          'wechatNumber': '',
          'aliUserId': '',
          'phone': '18801263882',
          'password': '',
          'headImage': 'https://caf-mall.oss-cn-beijing.aliyuncs.com/test/2022-12-12/6393036dc3c944329a818d4c0e04622b_background-3017167_640.jpg',
          'state': 0,
          'ifBlack': 0,
          'remark': '',
          'token': '',
          'memberLevelId': 15,
          'memberLevelName': '普通会员',
          'growth': 0,
          'credit': 455,
          'terminal': 0,
          'nextLevelGrowth': 3800,
          'nextLevelName': '黑钻会员',
          'registerIp': '',
          'lastLoginIp': '',
          'channelCode': '',
          'createTime': '2022-12-01 17:32:40',
          'updateTime': '',
          'notRead': 0,
          'waitPayOrderCount': 0,
          'waitSendOrderCount': 0,
          'waitReceiveOrderCount': 0,
          'totalOrderCount': 0,
          'totalCredit': 455,
          'afterCount': 0,
          'collectCount': 0,
          'askAnswerCount': 0,
          'commentCount': 0,
          'visitCount': 9,
          'isBusiness': 0,
          'shopId': 0
        },
        'errorData': {},
        'message': '成功',
        'name': '',
        'describe': '',
        'json': ''
      }
      if (res.code === '200') {
        this.setUserInfo(res.data)
      } else {
        this.$message.warning(res.message)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
$mainGlod: #c5aa7b; // 主题金
.notificationDetails {
  .head {
    width: 100%;
    height: 50px;
    line-height: 50px;
    font-size: 16px;
    display: flex;
    align-items: center;
    .arrow {
      background-image: url('../../../../static/image/xiangyou@2x.png');
      width: 5px;
      height: 10px;
      margin-right: 10px;
    }
  }
  .messageDetail {
    background: #FFFFFF;
    padding: 50px 0;
    min-height: 500px;
    h1 {
      font-size: 40px;
      font-weight: bold;
      color: #333333;
      text-align: center;
      margin-bottom: 20px;
    }
    .date {
      font-size: 14px;
      font-weight: 400;
      color: #666666;
      text-align: center;
      margin-bottom: 25px;
    }
    .messageInfo {
      min-height: 500px;
      p {
        font-size: 14px;
        color: #666666;
      }
    }
    .messageInfo >>> img{ // 修改v-html渲染的样式
      max-width: 100%;
      height: auto;
    }
  }
}
</style>
